# -*- coding:utf8 -*- #
# -----------------------------------------------------------------------------------
# ProjectName:  smart-meter-iot-test
# FileName:     report_data_body.py
# Author  :     
# Datetime:     2023/4/7 23:46
# Description： 水表上报数据定义。
# -----------------------------------------------------------------------------------
from random import randint
from typing import Dict, Union, Any

from common.util.logUtil.logUtil import LoggerUtil
from common.util.timeUtil.timeUtil import get_now_time
from core.mqtt.libProject.reportData.waterData import WaterData

logger = LoggerUtil()


def packge_report_data_body(useTtal: str, deviceNo: str) -> Dict[
    str, Union[Dict[Union[str, Any], Union[str, Any]], str]]:
    wd = WaterData()
    waterIncrement = wd.water_increment()
    allValue = (float(useTtal) + waterIncrement).__round__(2)
    reportBody = {
        "method": "thing.event.property.post",
        "params": {
            #  抄表时间
            "RealTimeDataReport:ReadTime": get_now_time(6),
            #  水表类型
            "RealTimeDataReport:Type": 1,
            "RealTimeDataReport:Version": "1234564",
            "RealTimeDataReport:Signal": 1,
            #  水表波特率
            "RealTimeDataReport:Baud": randint(0, 99999),
            #  累计用水量
            "RealTimeDataReport:UseTotal": allValue,
            "RealTimeDataReport:Iccid": "110",
            "RealTimeDataReport:DeviceNo": deviceNo,
            #  电池状态，0正常，1欠压
            "RealTimeDataReport:BatteryState": randint(0, 1),
            #  阀门状态，0开闸，1关闸
            # "RealTimeDataReport:GateState": randint(0, 1),
            "RealTimeDataReport:GateState": 0,
            #  上报周期，min
            "RealTimeDataReport:Interval": 15
        }
    }
    print(f'上报表号: {deviceNo},用水总量: {allValue},用水增量: {waterIncrement}')
    logger.debug(f'上报表号: {deviceNo},用水总量: {allValue},用水增量: {waterIncrement}')
    return reportBody


if __name__ == '__main__':
    pass
    # print(packge_report_data_body(1, 1, 1, 1))
